//
//  OrderSelectCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/8/26.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

class OrderSelectCell: BaseTableViewCell {
    
    @IBOutlet weak var leftImageView: UIImageView!
    
    @IBOutlet weak var topLabel: UILabel!
    
    
    @IBOutlet weak var bottomLabel: UILabel!
    
    
    @IBOutlet weak var rightBtn: UIButton!
    
    var models : [PaymentListModel]?
    
    var model : PaymentListModel?{
    
        didSet{
            
            if model == nil{
                return
            }
            
            
            if model!.payment_code == "wxpay_app" {
                
                leftImageView.image = UIImage(named: "payImage01")
                
                bottomLabel.text = "推荐安装微信5.0以上版本使用"
                
            }else if model!.payment_code == "alipay_app"{
                
                leftImageView.image = UIImage(named: "payImage04")
                bottomLabel.text = "推荐有支付宝账户的用户使用"

            
            }else{
                leftImageView.image = UIImage(named: "payImage02")
                bottomLabel.text = "使用快钱账户支付"

            
            }
        
            
            topLabel.text = model?.payment_name
            
            rightBtn.isSelected = model!.isSelect
        
        
        }
    
    
    
    }

  
    override func awakeFromNib() {
        super.awakeFromNib()
        contentView.backgroundColor = UIColor.white
        rightBtn.imageEdgeInsets = UIEdgeInsetsMake(20, 20, 20, 20)

        bottomLabel.textColor = UIColor.dakGray()

        
    }
    
    @IBAction func rightBtnDidTap(_ sender: UIButton) {
        
        if sender.isSelected == true {
            return
        }
        
        
        
        if model!.allowTap == false {
            
            let tempVC = UIAlertController(title: nil, message: "还需支付零元\n无需选择支付方式!", preferredStyle: .alert)
            
            let action1 = UIAlertAction(title: "确定", style: .destructive) { (action) in
                
                
                
            }
            
            
            
            let action2 = UIAlertAction(title: "取消", style: .default) { (action) in
                
                
                
            }
            
            tempVC.addAction(action2)
            tempVC.addAction(action1)
            
            viewController().present(tempVC, animated: true, completion: nil)
            
 
            
          
            return
        }

        
        
        
        
        
        
        if models != nil {
            
            for item in models! {
                
                item.isSelect = false
                
            }
            

        }
        
        
        sender.isSelected = !sender.isSelected
        
        model?.isSelect = sender.isSelected
        
        if viewController() is BaseViewController {
            
            let temp =  viewController() as! BaseViewController
            
            temp.plainTableView.reloadData()
            
        } else {
            
            let temp =  viewController() as! UITableViewController
            
            temp.tableView.reloadData()
        }
        
        
        
    }
    
    

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        

    }
    
    
}
